import { Application } from 'egg';
import {
    indexRule,
    createRule,
    baseRule,
    updateRule
} from '../validate/wx/feedback';

/**
 * 小程序路由
 */
export default (app: Application) => {
    const { header } = app.middleware;
    const { jwt } = app;

    return {
        'feedback.list': {
            method: 'GET',
            path: '/wx/feedback/list',
            options: {
                tags: ['feedback/list'],
                description: '意见反馈列表',
                handler: app.controller.wx.feedback.list,
                middlewares: [jwt, header()],
                validate: indexRule,
            },
        },
        'feedback.detail': {
            method: 'GET',
            path: '/wx/feedback/:id',
            options: {
                tags: ['feedback/detail'],
                description: '意见反馈详情',
                handler: app.controller.wx.feedback.detail,
                middlewares: [jwt, header()],
                validate: baseRule,
            },
        },
        'feedback.create': {
            method: 'POST',
            path: '/wx/feedback',
            options: {
                tags: ['feedback/create'],
                description: '新增意见反馈',
                handler: app.controller.wx.feedback.create,
                middlewares: [jwt, header()],
                validate: createRule,
            },
        },
        'feedback.update': {
            method: 'PUT',
            path: '/wx/feedback',
            options: {
                tags: ['feedback/update'],
                description: '更新意见反馈',
                handler: app.controller.wx.feedback.update,
                middlewares: [jwt, header()],
                validate: updateRule,
            },
        },
        'feedback.destroy': {
            method: 'DELETE',
            path: '/wx/feedback/:id',
            options: {
                tags: ['wx/feedback'],
                description: '删除意见反馈',
                handler: app.controller.wx.feedback.destroy,
                middlewares: [jwt, header()],
                validate: baseRule,
            },
        },
    };
};
